import { BelongsTo, Column, Comment, ForeignKey, Index, Model, Table, Unique } from 'sequelize-typescript';
import { User } from './user.model';
import { DataTypes } from 'sequelize';

@Table
export class Token extends Model<Token> {
  @Comment('会话ID (uid)')
  @Unique
  @Column({ type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false })
  uid: string;

  @Comment('用户ID')
  @Index
  @Column({ allowNull: false })
  account_id: string;

  @Comment('登录IP')
  @Column
  ip: string;

  // @Comment('签发时间')
  // @Column({ type: DataTypes.DATE, allowNull: false })
  // iat: Date;

  // @Comment('过期时间')
  // @Column({ type: DataTypes.DATE, allowNull: false })
  // exp: Date;

  @ForeignKey(() => User)
  @Column({ allowNull: false })
  userId: number;

  @BelongsTo(() => User)
  user: User;
}
